<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('用印外带') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('申请标题')" prop="applyTitle">
        <el-input v-model="queryParams.applyTitle" :placeholder="$t('申请标题')" size="small" @keyup.enter.native="queryHandle" />
      </el-form-item>
      <el-form-item :label="$t('申请人')" prop="applyUserId">
        <UserSelect v-model="queryParams.applyUserId" :placeholder="$t('申请人')" />
      </el-form-item>
      <el-form-item :label="$t('申请时间')" prop="applyTime">
        <DatePicker v-model="applyTimes" type="daterange" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['oa:sealOut:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t('新增') }}</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['oa:sealOut:export']"
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="exportHandle"
        >{{ $t("导出") }}</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="oaSealOutList" border tooltip-effect="darkTable">
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('申请标题')" align="center" show-overflow-tooltip prop="applyTitle">
        <template slot-scope="scope">
          <span class="link-type" @click="updateHandle(scope.row)">{{ scope.row.applyTitle }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('申请人')" align="center" prop="applyUserName" />
      <el-table-column :label="$t('申请时间')" align="center" prop="applyTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.applyTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('外带类型')" align="center" prop="takeoutType" :formatter="takeoutTypeFormat" />
      <el-table-column :label="$t('外出时间')" align="center" prop="absenceTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.absenceTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('预计归还时间')" align="center" prop="estimatedTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.estimatedTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('外出地点')" align="center" show-overflow-tooltip prop="destination" />
      <el-table-column :label="$t('备注')" align="center" show-overflow-tooltip prop="postscript" />
      <el-table-column :label="$t('审批状态')" fixed="right" align="center" width="120">
        <template slot-scope="scope">
          <ProcessStatus :status="scope.row.actStatus" :act-id="scope.row.actId" />
        </template>
      </el-table-column>
      <el-table-column :label="$t('操作')" align="center" fixed="right" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <!--            操作按钮-->
          <!--            包含：-->
          <!--            1.启动流程 流程状态不等于待审批,已完成 并且数据创建人等于当前用户时展示-->
          <!--            2.终止流程 流程状态等于待审批并且数据创建人等于当前用户时展示-->
          <!--            3.删除 同启动流程-->

          <ListBtn :bus-data="scope.row" has-permi="oa:sealOut" />
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改【用印外带】对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <oaSealOutForm ref="oaSealOutForm" />
    </el-dialog>
  </div>
</template>

<script>
import { listOaSealOut, delOaSealOut } from '@/api/oa/seal/oaSealOut'
import oaSealOutForm from './oaSealOutForm.vue'
export default {
    components: {
        oaSealOutForm
    },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 【用印外带】表格数据
          oaSealOutList: [],
          // 弹出层标题
          title: '编辑用印外带',
          // 是否显示弹出层
          formOpen: false,
          //
          takeoutTypeOptions: [],
          // 申请时间 参数
          applyTimes: [],
          // 查询参数
          queryParams: {
              applyTitle: undefined,
              applyUserId: undefined,
              applyTime: undefined,
              takeoutType: [],
              absenceTime: undefined,
              estimatedTime: undefined,
              destination: undefined,
              peersUser: [],
              postscript: undefined,
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {}
      }
  },
  created() {
      this.getList()
      // 通知方式 字典
      this.getDicts('takeout_type').then(response => {
        this.takeoutTypeOptions = response.data
      })
  },
  methods: {
    /** 查询【用印外带】列表 */
    getList() {
        this.loading = true
        // 时间参数赋值
        if (this.applyTimes != null && this.applyTimes.length > 1) {
          this.queryParams.startDate = this.applyTimes[0]
          this.queryParams.endDate = this.applyTimes[1]
        } else {
          this.queryParams.startDate = undefined
          this.queryParams.endDate = undefined
        }
        listOaSealOut(this.queryParams).then(response => {
            this.oaSealOutList = response.rows
            this.total = response.total
            this.loading = false
        })
    },

    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            applyTitle: undefined,
            applyUserId: undefined,
            applyTime: undefined,
            takeoutType: [],
            absenceTime: undefined,
            estimatedTime: undefined,
            destination: undefined,
            peersUser: [],
            postscript: undefined,
            createBy: undefined,
            createTime: undefined,
            updateBy: undefined,
            updateTime: undefined,
            delFlag: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.applyTimes = []
        this.resetForm('queryForm')
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.$nextTick(() => {
            this.$refs.oaSealOutForm.init(null)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.oaSealOutForm.init(row)
        })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(() => {
            return delOaSealOut(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(() => {
        })
    },
    /** 导出按钮操作 */
    exportHandle() {
      this.downLoadExcel('/out/oaSealOut/export', this.queryParams)
    },
    // 通知方式字典翻译
    takeoutTypeFormat(row) {
      return this.selectDictLabels(this.takeoutTypeOptions, row.takeoutType)
    }
  }
}
</script>
